﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Atosenet.Data
{
    public struct IADCode
    {
        #region 成员

        public static readonly IADCode Empty = new IADCode(0, 0, 0);

        public const int IAD_CODE_LENGTH = 3;

        #endregion


        #region 初始化

        public IADCode(byte industryCode, byte applicationCode, byte dataTypeCode)
            : this()
        {
            IndustryCode = industryCode;
            ApplicationCode = applicationCode;
            DataTypeCode = dataTypeCode;
        }

        #endregion


        #region 公开函数

        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
                return false;

            IADCode code = (IADCode)obj;
            return (code.GetHashCode() == this.GetHashCode());
        }

        public override int GetHashCode()
        {
            return (IndustryCode * 1000000 + ApplicationCode * 1000 + DataTypeCode);
        }

        public override string ToString()
        {
            return string.Format("IAD Code([IndustryCode]={0},[ApplicationCode]={1},[DataTypeCode]={2})",
                IndustryCode,
                ApplicationCode,
                DataTypeCode);
        }

        #endregion


        #region 静态函数

        public static bool Equals(IADCode iad1, IADCode iad2)
        {
            return (iad1.IndustryCode == iad2.IndustryCode &&
                iad1.ApplicationCode == iad2.ApplicationCode &&
                iad1.DataTypeCode == iad2.DataTypeCode);
        }

        public static bool operator ==(IADCode code1, IADCode code2)
        {
            return (code1.IndustryCode == code2.IndustryCode &&
                code1.ApplicationCode == code2.ApplicationCode &&
                code1.DataTypeCode == code2.DataTypeCode);
        }

        public static bool operator !=(IADCode code1, IADCode code2)
        {
            return !(code1 == code2);
        }

        public static bool IsEmpty(IADCode iad)
        {
            return iad == Empty;
        }

        #endregion


        #region 属性

        public byte IndustryCode
        {
            get;
            set;
        }

        public byte ApplicationCode
        {
            get;
            set;
        }

        public byte DataTypeCode
        {
            get;
            set;
        }

        public int Length
        {
            get { return IAD_CODE_LENGTH; }
        }

        #endregion
    }
}
